package com.wn.production.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.PageBean;
import com.wn.entity.WorkOrder;
import com.wn.production.mapper.WorkOrderMapper;
import com.wn.production.mapper.WorkOrderStockMapper;
import com.wn.production.service.WorkOrderService;
import com.wn.production.vo.WorkOrderVo;
import com.wn.utils.CurrentTime;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkOrderMapperImpl implements WorkOrderService {
    @Autowired
    private   WorkOrderMapper workOrderMapper;
    @Autowired
    private WorkOrderStockMapper workOrderStockMapper;
    /**
     * @param workOrder
     * @return void
     * @ author zc
     * @ date 2022/10/24 17点21分
     * @ Description 增加工单
     */
    @Override
    public void insert(WorkOrder workOrder) {
        String workorderNumber="WN-A"+ CurrentTime.getCurrentTimeString();
        workOrder.setWorkorderNumber(workorderNumber);
        workOrderStockMapper.insert(workOrder.getWorkorderStocks());
        workOrderMapper.insert(workOrder);
    }
    /**
     * @param workOrderVo
     * @return java.util.List<com.wn.entity.WorkOrder>
     * @ author zc
     * @ date 2022/10/24 17点48分
     * @ Description 多条件分页查询工单信息
     */
    @Override
    public PageBean<WorkOrder> getByCondition(WorkOrderVo workOrderVo) {
        Page<WorkOrder> page = PageHelper.startPage(workOrderVo.getCurrPage(), workOrderVo.getPageSize());
        List<WorkOrder> list = workOrderMapper.getByCondition(workOrderVo.getWorkOrder());
        return PageBeanUtil.getPageBean(list,page,workOrderVo.getCurrPage(),workOrderVo.getPageSize());

    }

    @Override
    public List<WorkOrder> getByConditionn(WorkOrder workOrder) {
        return workOrderMapper.getByCondition(workOrder);
    }

    /**
     * @return java.util.List<com.wn.entity.WorkOrder>
     * @ author zc
     * @ date 2022/10/24 17点48分
     * @ Description 查询全部工单信息
     */
    @Override
    public PageBean<WorkOrder> getAll(WorkOrderVo workOrderVo) {
        Page<WorkOrder> page = PageHelper.startPage(workOrderVo.getCurrPage(), workOrderVo.getPageSize());
        List<WorkOrder> list = workOrderMapper.getByCondition(workOrderVo.getWorkOrder());
        return PageBeanUtil.getPageBean(list,page,workOrderVo.getCurrPage(),workOrderVo.getPageSize());
    }
    /**
     * @param workOrder
     * @return void
     * @ author zc
     * @ date 2022/10/24 17点21分
     * @ Description 修改工单状态及人员分配
     */
    @Override
    public void update(WorkOrder workOrder) {
        workOrderMapper.update(workOrder);

    }
}
